﻿using System;
using System.Reflection;
using System.ServiceModel;
using Tinter.Application.Modules.Finance.Services;
using Tinter.Application.Modules.Finance.DTOs;
using Tinter.Common.Pagination;
using Tinter.DistributedServices.InstanceProviders;

namespace Tinter.DistributedServices.Modules.Finance
{
    [UnityInstanceProviderServiceBehavior] //create instance and inject dependencies using unity container
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class FinanceService : IFinanceService
    {
        #region Members

        private readonly IFinanceAppService financeAppService;

        #endregion

        #region Constructor

        /// <summary>
        /// Creates a new instance of finance module service.
        /// </summary>
        /// <param name="financeAppService">The finance application service dependency</param>
        public FinanceService(IFinanceAppService financeAppService)
        {
            if (financeAppService == null)
            {
                throw new ArgumentNullException(MethodBase.GetCurrentMethod().GetParameters()[0].Name);
            }

            this.financeAppService = financeAppService;
        }

        #endregion

        #region IFinanceService Members

        /// <summary>
        /// <see cref="IFinanceService"/>
        /// </summary>
        /// <param name="userId"><see cref="IFinanceService"/></param>
        /// <param name="pageNumber"> </param>
        /// <param name="pageSize"> </param>
        /// <returns><see cref="IFinanceService"/></returns>
        public PagedItems<MyExpenseProjectDto> FindExpenseProjects(Guid userId, int pageNumber, int pageSize)
        {
            return this.financeAppService.GetExpenseProjects(userId, pageNumber, pageSize);
        }

        /// <summary>
        /// <see cref="IFinanceService"/>
        /// </summary>
        /// <param name="dtoMyExpenseProject"><see cref="IFinanceService"/></param>
        /// <returns><see cref="IFinanceService"/></returns>
        public MyExpenseProjectDto CreateExpenseProject(MyExpenseProjectDto dtoMyExpenseProject)
        {
            return this.financeAppService.AddExpenseProject(dtoMyExpenseProject);
        }

        #endregion
    }
}
